﻿using System;
using System.Collections.Generic;
using System.Text;

namespace JinianNet.Common
{
    public class Url
    {
        public static string Concat(params string[] args)
        {
            if (args == null || args.Length == 0)
                return null;
            return Utils.Replace(string.Join("/", args).Replace(System.IO.Path.DirectorySeparatorChar, '/'), "//", "/").Replace(":/", "://");
        }

        public static string MapPath(string path)
        {
            System.Web.HttpContext context = System.Web.HttpContext.Current;
            if (context != null)
            {
                return context.Server.MapPath(path);
            }
            else
            {
                if (path.StartsWith("~"))
                    return Path.Concat(path.Replace("~", JinianNet.Web.HttpRunInfo.AppDomainAppPath));
                return Path.Concat(JinianNet.Web.HttpRunInfo.AppDomainAppPath, path);
            }
        }
    }
}
